package com.fire.control.system.entity;

import java.util.Collection;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonManagedReference;

@Entity
@Table(name = "t_roles") 
public class Role extends BaseEntity{

	private static final long serialVersionUID = 1L;
	
	@Column(name = "role_type", nullable = false,length=50)
	private String roleType;
	
	@Column(name = "role_name", nullable = false,length=50)
	private String roleName;
	
	@JsonManagedReference
	@ManyToMany(cascade={CascadeType.REFRESH},fetch = FetchType.LAZY)
	@JoinTable(name="t_role_resource",
		joinColumns=@JoinColumn(name="role_id"),
		inverseJoinColumns=@JoinColumn(name="resource_id"))
	private Collection<Resource> resources;
	
	@JsonBackReference
	@ManyToOne(cascade={CascadeType.REFRESH},fetch = FetchType.EAGER)  
	@JoinColumn(name="company_id") 
	private Company company;
	
	public Company getCompany() {
		return company;
	}

	public void setCompany(Company company) {
		this.company = company;
	}

	public Collection<Resource> getResources() {
		return resources;
	}

	public void setResources(Collection<Resource> resources) {
		this.resources = resources;
	}

	public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	public String getRoleType() {
		return roleType;
	}

	public void setRoleType(String roleType) {
		this.roleType = roleType;
	}

}
